package helper;

public class Coder {
	private String projectName = "frame_work_git";
	public String root = null;
	public String vmPath = null;
	private String subPackageName = "rms";
	private String rootpackage = "com.frame.app.core";
	private String folder = "/src/com/frame/app/core/";
	private String jdbcDriver = "com.mysql.jdbc.Driver";
	private String dbUrl = "jdbc:mysql://localhost:3306/frame_work";
	private String dbUser = "root";
	private String dbPassword = "root";
//	private String jdbcDriver = "oracle.jdbc.driver.OracleDriver";
//	private String dbUrl = "jdbc:oracle:thin:@202.101.116.85:1510:XDWDB";
//	private String dbUser = "ct_ecp";
//	private String dbPassword = "ct_ecp";	
	// 填写表名
	private String[] tableName = new String[] { "system_menu"};
	public Coder() {
		String path = Coder.class.getResource("/").getPath().substring(1);
		this.vmPath = path + "helper/vm";
		System.out.println("===========" + vmPath);
		this.root = path.substring(0, path.indexOf(projectName)) + projectName;
		System.out.println("===========" + this.root);
	}
	// 生成ibatis,Spring等配置文件
	public void config() {
		System.out.println("----config start--------");
//		String[] packageName = new String[] { "user/ibatis/" };
//		String[] filePath = new String[] { root + "/WebRoot/WEB-INF/conf/sqlMapConfig.xml" };
//		String[] vm = new String[] { "addIBatisSpringConfig.vm" };
//		AutoCoder autocoder = AutoCoder.getInstance();
//		autocoder.setDatabaseInfo(jdbcDriver, dbUrl, dbUser, dbPassword);
//      autocoder.addSpringConfiger(tableName, packageName, filePath, vmPath, vm);
		System.out.println("------config over-----");
	}

	// 生成代码文件
	public void code() {
		System.out.println("------code start------");
		String[] packageName = new String[] {
				rootpackage + "." + subPackageName + ".model",
				rootpackage + "." + subPackageName + ".mybatis",
				rootpackage + "." + subPackageName + ".mybatis",
				"com.frame.app.backstage" + "." + subPackageName + ".controller"};
		String[] filePath = new String[] {
				root + folder + subPackageName + "/model/",
				root + folder + subPackageName + "/mybatis/",
				root + folder + subPackageName + "/mybatis/",
				root + "/src/com/frame/app/backstage/" + subPackageName + "/controller/"};
		String[] vm = new String[] { "model.vm", "mapper.vm", "mybatisXml.vm","controller.vm" };

		AutoCoder autocoder = AutoCoder.getInstance();
		autocoder.setDatabaseInfo(jdbcDriver, dbUrl, dbUser, dbPassword);
		autocoder.setAuthor("chen");
		autocoder.setEmail("chenxilongno1@163.com");

		try {
			autocoder.codeAll(tableName, filePath, vmPath, packageName, vm ,subPackageName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println("------code over.------");
	}

	public static void main(String[] args) {
		Coder coder = new Coder();
		coder.code();
		// coder.config();
	}

}
